home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / SLTPU70C / SAMPLE3.PAS < prev    next >
Pascal/Delphi Source File  |  1991-07-10  |  1KB  |  50 lines

  1.  
  2. Program Sample3;
  3.  
  4.   { Sample program to list users in alphabetical order via recursion }
  5.  
  6.  
  7. Uses Filedef,Users;
  8.  
  9. var r: longint;
  10.     localuser: usertype;
  11.  
  12.  
  13.     Procedure ProcessUser (var user: usertype);
  14.     Begin
  15.       writeln(user.name,', ',user.location);
  16.     end;
  17.  
  18.  
  19.     Procedure ReadUserList (n: longint);
  20.     Begin
  21.       ReadUser(localuser,n);
  22.       if localuser.leaf.left<>0 then begin
  23.         ReadUserList(localuser.leaf.left);    { process left branch }
  24.         ReadUser(localuser,n);                { re-read current record }
  25.       end;
  26.  
  27.       ProcessUser(localuser);                 { perform action on user }
  28.  
  29.       if (localuser.leaf.right<>0)            { process right branch }
  30.         then ReadUserList(localuser.leaf.right);
  31.     end;
  32.  
  33.     { Notice that the recursive procedure does not declare any local
  34.       variables, and that all processing of the user (ie. printing out
  35.       of the name) is done in a separate procedure. This helps keep
  36.       the required stack space to a minimum. }
  37.  
  38.  
  39. Begin
  40.   if OpenFiles([CONFIGF,NODESF]) and OpenUserFile then begin
  41.  
  42.     ReadUserList(UserFileRoot);
  43.       { begin recursive procedure at user file root }
  44.  
  45.     CloseUserFile;
  46.     CloseAllFiles;
  47.   end
  48.   else writeln('Could not open CONFIG File');
  49.  
  50. end.